package com.movie.demo.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movie.demo.mapper.UserMapper;
import com.movie.demo.pojo.User;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Console;
import java.util.List;
import java.util.Objects;

@Service
@Transactional
public class UserService extends ServiceImpl<UserMapper, User> implements com.movie.demo.service.UserService {

    public User login(String account, String password) {
        EntityWrapper<User> userW = new EntityWrapper<User>();
        userW.eq("account",account);
        userW.eq("password",password);
        return this.selectOne(userW);
    }

    @Override
    public Boolean register(User user) {
        User user1 = this.selectOne(new EntityWrapper<User>().eq("name", user.getName()).or().eq("account", user.getAccount())
                .or().eq("userphone", user.getUserphone()));
        if (Objects.isNull(user1)||user1==null){
            this.insert(user);
            return true;
        }
        return false;
    }

    @Override
    public List<User> select() {
        List<User> userList = this.selectList(new EntityWrapper<User>());
        return userList;
    }

    @Override
    public boolean updateUser(User user) {

        return this.updateById(user);
    }

    @Override
    public boolean deleteUser(Integer userID) {
        boolean flag = this.deleteById(userID);
        return flag;
    }

    @Override
    public List<User> serachuser(String usersearch) {
        List<User> userList=this.selectList(new EntityWrapper<User>().like("account",usersearch).or().like("name",usersearch));
        return userList;
    }
}
